package org.ch02.job.test02;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author XCH
 * @date 2025 - 03 - 17
 */
public class BeanUtil {
    /**
     * 创建类的实例并调用指定方法
     *
     * @param className  类名
     * @param methodName 方法名
     * @param param      方法参数
     */
    public static void ConstructorAndMethod(String className, String methodName, String param){
        try {
            Class<?> clazz = Class.forName(className);
            Constructor<?> constructor = clazz.getDeclaredConstructor();
            Object obj = constructor.newInstance();
            Method method = clazz.getMethod(methodName, String.class);
            method.invoke(obj, param);

        } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException |
                 InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
}
